<template>
	<view>
		<u-navbar :is-back="true" title="资质认证" title-color="white" back-icon-color="#FFFFFF" :background="background"
			:border-bottom="false">
		</u-navbar>

		<!-- 头部   -->
		<u-row v-if="true" gutter="16" class="u-p-15 u-font-12" style="background-color: #00a8ff;color: #bcdeff;">
			<u-col span="4">
				<view class="demo-layout bg-purple" style="text-align: center;">
					<image style="width: 25rpx;height: 25rpx;" class="u-m-r-16"
						src="../../../static/index/zzrz/topw.png"></image>
					<span style="color: #bcdeff;">基础信息</span>
				</view>
			</u-col>
			<u-col span="4">
				<view class="demo-layout bg-purple" style="text-align: center;">
					<image style="width: 25rpx;height: 25rpx;" class="u-m-r-16"
						src="../../../static/index/zzrz/topw.png"></image>
					<span style="color: #bcdeff;">实名认证</span>
				</view>
			</u-col>
			<u-col span="4">
				<view class="demo-layout bg-purple" style="text-align: center;">
					<image style="width: 25rpx;height: 25rpx;" class="u-m-r-16"
						src="../../../static/index/zzrz/topd.png"></image>
					<span style="color: #bcdeff;">资质认证</span>
				</view>
			</u-col>
		</u-row>
		<view class="u-p-15 u-font-12" style="background-color: #f3f4f5;color: #b2b2b2;">
			请上传医生资质文件照片，敏感信息可打码马赛克
		</view>
		<!-- 医生资格证 -->
		<view class="u-padding-left-26 u-padding-right-26 u-margin-bottom-26">
			<h4 class="u-padding-top-20 u-padding-bottom-20">医生资格证</h4>
			<u-row gutter="16">
				<u-col span="6">
					<view class="demo-layout bg-purple">
						<image src="../../../static/index/zzrz/sysl.png" mode="" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
				<u-col span="6">
					<view class="demo-layout bg-purple-light">
						<image :src="zgz" mode="" @click="chooseImage(1)" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
			</u-row>
			<u-row gutter="16">
				<u-col span="6">
					<view class="demo-layout bg-purple">
						<image src="../../../static/index/zzrz/xqsl.png" mode="" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
				<u-col span="6">
					<view class="demo-layout bg-purple-light">
						<image :src="zgzShow" mode="" @click="chooseImage(2)" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="u-padding-left-26 u-padding-right-26">
			<h4 class="u-padding-top-20 u-padding-bottom-20">医生执业证</h4>
			<u-row gutter="16">
				<u-col span="6">
					<view class="demo-layout bg-purple">
						<image src="../../../static/index/zzrz/zysysl.png" mode="" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
				<u-col span="6">
					<view class="demo-layout bg-purple-light">
						<image :src="zyz" mode="" @click="chooseImage(3)" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
			</u-row>
			<u-row gutter="16">
				<u-col span="6">
					<view class="demo-layout bg-purple">
						<image src="../../../static/index/zzrz/zyxm.png" mode="" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
				<u-col span="6">
					<view class="demo-layout bg-purple-light">
						<image :src="zyzShow" mode="" @click="chooseImage(4)" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
			</u-row>
			<u-row gutter="16">
				<u-col span="6">
					<view class="demo-layout bg-purple">
						<image src="../../../static/index/zzrz/zynew.png" mode="" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
				<u-col span="6">
					<view class="demo-layout bg-purple-light">
						<image :src="zxsl" mode="" style="width: 100%;height: 250rpx;">
						</image>
					</view>
				</u-col>
			</u-row>
		</view>
		<u-cell-group style="padding: 0rpx 26rpx;background-color: #FFFFFF;">
			<u-cell-item title="编号" :arrow="false">
				<input type="text" placeholder="请输入15位证件编码" placeholder-style="text-align: right;font-size: 24rpx;"
					v-model="bianhao" style="" />
			</u-cell-item>
			<u-cell-item title="有效期" @click="showPicker=true" :value="youxiao"></u-cell-item>
			<u-picker mode="time" v-model="showPicker" :params="params" @confirm="confirm"></u-picker>
		</u-cell-group>
		<u-button v-if="" type="primary" style="width: 90%;margin: 26px auto;" @click="end()">提交审核</u-button>

		<u-popup v-model="show" mode="center">
			<u-image width="380rpx" height="460rpx" src="../../../static/index/zzrz/sh.png" @click="returnIndex()">
			</u-image>
		</u-popup>

	</view>
</template>

<script>
	import {
		ossAccessid,
		ossHost,
		ossSignature,
		ossPolicyBase64
	} from "@/common/ossUploadfile.js"
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#00a8ff',
				},
				value: 'orange',
				show: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				showPicker: false,
				// 编号和有效期
				bianhao: '',
				youxiao: '请输入证件有效期',
				timestamp1: '',
				// 资格证 资格证详情 执业证 执业证详情
				zgz: '../../../static/index/zzrz/zgzsy.png',
				zgzShow: '../../../static/index/zzrz/zgzxqy.png',
				zyz: '../../../static/index/zzrz/sy.png',
				zyzShow: '../../../static/index/zzrz/xingming.png',
				zxsl: '../../../static/index/zzrz/zyzgxbg.png',
				
				zgzz: '../../../static/index/zzrz/zgzsy.png',
				zgzShowz: '../../../static/index/zzrz/zgzxqy.png',
				zyzz: '../../../static/index/zzrz/sy.png',
				zyzShowz: '../../../static/index/zzrz/xingming.png',
				zxslz: '../../../static/index/zzrz/zyzgxbg.png',
			}
		},
		methods: {
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				console.log(e);
			},
			openinfo(url) {
				uni.navigateTo({
					url: url,
				});
			},
			returnIndex() {
				this.show = false;
				uni.switchTab({
					url: '/pages/tabBar/index/index'
				})
			},
			confirm(e) {
				console.log(e);
				this.youxiao = e.year + "年" + e.month + "月" + e.day + "日";
				let dt = e.year + "-" + e.month + "-" + e.day + " " + "00:00";
				var timestamp1 = (new Date(dt)).getTime() / 1000
				console.log("时间戳:", timestamp1);
				console.log("日期:", dt);
				this.timestamp1 = timestamp1;
			},

			chooseImage(index) {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					// sourceType: ['album'], //从相册选择
					success: (res) => {
						console.log(res.tempFilePaths)
						let nameStr = res.tempFilePaths[0];
					
						nameStr = nameStr.split("/");
						console.log(nameStr);
						for (let k in nameStr) {
							nameStr += nameStr[k];
						}

						nameStr = nameStr.replace(
							/[\ |\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\||\\|\[|\]|\{|\}|\;|\:|\"|\'|\,|\<|\.|\>|\/|\?]/g,
							"")
						console.log("去除所有，号" + nameStr)
						let timestamp = (new Date()).valueOf();
						console.log(timestamp);
						nameStr = "test1/" + timestamp + "/" + nameStr + "a.png";
						console.log("nameStr:" + nameStr);
						console.log("res:" + res);
						let titleImage = ossHost + "/" + nameStr;
						console.log(titleImage);
						console.log("index: " + index);
						switch (index) {
							case 1:
								setTimeout((res) => {
									this.zgz = titleImage;
									this.zgzz=nameStr;
								}, 3000)

								break;
							case 2:
								setTimeout((res) => {
									this.zgzShow = titleImage;
									this.zgzShowz=nameStr;
								}, 3000)

								break;
							case 3:
								setTimeout((res) => {
									this.zyz = titleImage;
									this.zyzz=nameStr;
								}, 3000)

								break;
							case 4:
								setTimeout((res) => {
									this.zyzShow = titleImage;
									this.zyzShowz=nameStr;
								}, 3000)
								break;
						}

						uni.uploadFile({
							url: ossHost,
							filePath: res.tempFilePaths[0],
							fileType: "image",
							name: 'file',
							formData: {
								"key": nameStr,
								'OSSAccessKeyId': ossAccessid,
								'policy': ossPolicyBase64,
								'signature': ossSignature,
								'success_action_status': 200
							},
							header: {},
							success: obsRes => {
								uni.hideLoading();
								console.log(obsRes)
								if (obsRes.statusCode == 200) {
									uni.showToast({
										title: "图片上传成功",
										duration: 800
									})
								} else {
									uni.showToast({
										title: "上传失败,请检查网络或服务器", // 
										icon: "none",
									})
								}
							},
							fail: err => {
								console.log("报错")
								uni.hideLoading()
								uni.showToast({
									title: "网络错误请检查," + JSON.stringify(err),
									icon: "none",
									duration: 4000
								})
							},
						});
					}
				});
			},

			end() {
				// 医生身份认证
				// 执业机构  名称地址 详细地址
				let workingagency = uni.getStorageSync('value1');
				let workingagency_address = uni.getStorageSync('input');
				let workingagency_area = uni.getStorageSync('value2');
				// 头像地址
				let avatar = uni.getStorageSync('avatar');
				// 真实姓名
				let nickname = uni.getStorageSync('nickname');
				// 职称
				let positions_id = uni.getStorageSync('positions_id');
				// 执业开始时间
				let workingtime = uni.getStorageSync('workingtime');
				// 擅长项目 ids
				let collection_ids = uni.getStorageSync('collection_ids');
				// 个人简介
				let description = uni.getStorageSync('description');
				console.log(collection_ids)
				// 擅长项目 ids
				// 身份证正面，身份证背面
				let selfthing = uni.getStorageSync('selfthing');
				console.log(description)
				let zm = uni.getStorageSync('zm');
				console.log(zm);
				let fm = uni.getStorageSync('fm');

				let sex = uni.getStorageSync('sex');

				let phone = uni.getStorageSync('phone');

				let work = {};
				work['ident_p'] = zm;
				work['ident_n'] = fm;
				work['p_image'] = this.zgzz;
				work['d_image'] = this.zgzShowz;
				work['w_p_image'] = this.zyzz;
				work['w_d_image'] = this.zyzShowz;
				work['bn'] = this.bianhao;
				work['endtime'] = this.timestamp1;
				console.log(work);
				// 清除缓存
				// uni.removeStorageSync('storage_key');
				let data = {
					avatar: avatar,
					nickname: nickname,
					workingagency: workingagency,
					workingagency_area: workingagency_area,
					workingagency_address: workingagency_address,
					position_id: positions_id,
					workingtime: workingtime,
					collection_ids: collection_ids,
					description: description,
					selfthing: selfthing,
					gender: sex,
					mobile: phone,
					working: work
				}
				console.log(data);
				uni.request({
					url: "http://www.seoutr.com/api/doctors.ident/certification",
					method: "POST",
					dataType: "JSON",
					header: {
						'token': uni.getStorageSync('userInfo').token
					},
					data: {
						avatar: avatar,
						nickname: nickname,
						workingagency: workingagency,
						workingagency_area: workingagency_area,
						workingagency_address: workingagency_address,
						position_id: positions_id,
						workingtime: workingtime,
						collection_ids: collection_ids,
						description: description,
						selfthing: selfthing,
						gender: sex,
						mobile: phone,
						working: work
					},
					complete: (res) => {
						console.log("请求成功");
						console.log(res);
						console.log(res.statusCode);
						if (res.statusCode == "200") {
							this.show = true;
						}
					},
					fail: (err) => {
						console.log("发生了一个错误")
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">

</style>
